package com.example.controller;

import com.example.common.Result;
import com.example.common.ResultUtils;
import com.example.dto.CashOutRequest;
import com.example.dto.TransferRequest;
import com.example.service.AccountService;
import com.example.service.CashOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
@description:
@ClassName AccountController
@author chen
@create 2025-08-26 10:55
@Version 1.0
*/
@RestController
@RequestMapping("/account")
public class AccountController
{

    @Autowired
    private AccountService accountService;

    @Autowired
    private CashOutService cashOutService;


    @RequestMapping("/transfer")
    public Result<Boolean> transfer(@RequestBody TransferRequest request)
    {
        this.accountService.transfer(request.getFromAccountId(), request.getToAccountId(), request.getTransferPrice());
        return ResultUtils.success(Boolean.TRUE);
    }


    @RequestMapping("/cashOut")
    public Result<Boolean> cashOut(@RequestBody CashOutRequest request)
    {
        // 这里可以先拿到用户ID
        String accountId = "1";
        this.cashOutService.cashOut(accountId, request.getPrice());
        return ResultUtils.success(Boolean.TRUE);
    }
}
